/**
 * Project Name:gc.sms.mvn
 * File Name:PositionServiceImpl.java
 * Package Name:com.clps.dev.sms.service.impl
 * Date:2018-11-16 11:22:50
 * Copyright (c) 2018,http://www.clpsglobal.com/zh/home-cn/ All Rights Reserved.
 *
 */
package com.clps.dev.sms.service.sm.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.clps.dev.sms.common.CommonData;
import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.common.result.ResultType;
import com.clps.dev.sms.common.service.impl.BaseServiceImpl;
import com.clps.dev.sms.dao.sm.PositionDao;
import com.clps.dev.sms.entity.sm.Position;
import com.clps.dev.sms.service.sm.IPositionService;
import com.clps.dev.sms.util.result.ResponseResultUtil;

/**
 * ClassName: PositionServiceImpl <br/>
 * Description: PositionServiceImpl.class<br/>
 * <br/>
 *
 * @author Jack.Huang
 * @version V1.0
 * @since JDK 1.8
 * @date:2018-11-16 11:22:50
 */
@Service
public class PositionServiceImpl extends BaseServiceImpl<Position> implements IPositionService {

	@Autowired
	private PositionDao positionDao;
	
	private Logger logger = Logger.getLogger(PositionServiceImpl.class);
	

	public PositionServiceImpl() {
		super(Position.class);
	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IPositionService#addPosition(com.clps.dev.sms.entity.sm.Position)
	 */
	@Override
	public ResponseResult<Position> addPosition(Position position) {
		if(position==null) {
			logger.error("position不能为空");
			return  ResponseResultUtil.error(ResultType.OBJECT_NULL);
		}
		if(position.getPositionName()==null
				||position.getPositionCreateName()==null||position.getPositionCreateTime()==null
				||position.getPositionUpdatedEmployeeName()==null) {
			logger.error("这个字段不能为空");
			return ResponseResultUtil.error(ResultType.INPUT_NULL);
		}
		int label = positionDao.save(position);
		if(label>0) {
			return ResponseResultUtil.success(ResultType.ADD_SUCCESS);
		}else {
			return ResponseResultUtil.error(ResultType.ADD_FAULT);
		}

	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IPositionService#deletePosition(com.clps.dev.sms.entity.sm.Position)
	 */
	@Override
	public String deletePosition(Integer id) {
		int lable = positionDao.deleteById(id);
		if(lable>0) {
			return CommonData.DELETE_SUCCESS;
		}else {
			return CommonData.DELETE_FAILURE;
		}
	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IPositionService#queryPositionById(java.lang.Integer)
	 */
	@Override
	public ResponseResult<Position> queryPositionById(Integer id) {
		Position position = positionDao.queryById(id);
		return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,position);
	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IPositionService#queryAllPosition()
	 */
	@Override
	public ResponseResult<Position> queryAllPosition(Integer currPage ,Integer pageSize,String name) {
		return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,queryByPageName(currPage, pageSize, name));
	}
	public ResponseResult<Position> queryAllPosition() {
		List<Position> list = positionDao.queryALl();
		return ResponseResultUtil.success(ResultType.QUERY_SUCCESS,list);
	}

	/**
	 * 
	 * @see com.clps.dev.sms.service.sm.IPositionService#editPosition(com.clps.dev.sms.entity.sm.Position)
	 */
	@Override
	public ResponseResult<Position> editPosition(Position position) {
		if(position==null) {
			logger.error("position不能为空");
			return ResponseResultUtil.error(ResultType.OBJECT_NULL);
		}
		if(position.getPositionName()==null
				||position.getPositionCreateName()==null
				||position.getPositionUpdatedEmployeeName()==null) {
			logger.error("这个字段不能为空");
			return ResponseResultUtil.error(ResultType.INPUT_NULL);
		}
		int lable = positionDao.update(position, position.getPositionId());
		if(lable>0) {
			return ResponseResultUtil.success(ResultType.UPDATE_SUCCESS);
		}else {
			return ResponseResultUtil.error(ResultType.UPDATE_FAULT);
		}
	}

}
